package com.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.manage.model.Menu;
import com.manage.model.User;
import com.manage.service.MenuService;

@Controller
public class MenuController {
@Autowired
private MenuService menuService;

//菜单查询
@RequestMapping(value="menulist2",method = RequestMethod.POST)
public ModelAndView listMenu(){
	ModelAndView mav = new ModelAndView("jsonView");	
	try {
		List<Menu> menuList = menuService.listAllMenus();
			System.out.println("菜单列表"+menuList);
			mav.addObject("menulist", menuList);
			mav.addObject("success",true);
	} catch (Exception e) {
		mav.addObject("success", false);
	}
	return mav;
}

@RequestMapping(value = "getMenu")
public ModelAndView getMenu(HttpServletRequest request,@RequestParam(value="userid") int userid) {
	ModelAndView mav =new ModelAndView("jsonView");
	String username = request.getParameter("username");
	String password = request.getParameter("password");
	User user = new User();
	user.setUserid(userid);
	user.setUsername(username);
	user.setPassword(password);
	Integer roleid=user.getRoleid();
	menuService.selectMenuByRoleId(roleid);
	mav.setViewName("nenulist.do?userid=${user.userid}");
	return mav;
}

//菜单保存
@RequestMapping(value="saveMenu")
public ModelAndView saveMenu(Menu menu){
	ModelAndView mav = new ModelAndView("jsonView");
	menuService.saveMenu(menu);
	mav.addObject("success",true);
	mav.setViewName("views/menuresult");
	return mav;
}
}
